/* Includes ------------------------------------------------------------------*/
#include "main.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
#define CRC16_POLY 0x8005
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
volatile uint8_t CrcHi;
volatile uint8_t CrcLo;
/* Referencing variables -----------------------------------------------------*/
/* Private function ----------------------------------------------------------*/
/* Referencing functions -----------------------------------------------------*/
void CalcCRC(uint8_t *ptr,uint8_t Length)
{
     uint8_t i,CrcData;
     uint16_t CheckSum = 0xFFFF;
     while (Length --)
     {
        CrcData = * (ptr ++);
        for (i=0u;i<8u;i++)
        {
           if (((CheckSum & 0x8000) >> 8) ^ (CrcData & 0x80))
              CheckSum = (CheckSum << 1) ^ CRC16_POLY;
           else
              CheckSum = (CheckSum << 1);
           CrcData <<= 1;
        }   
     }
     CrcHi = CheckSum >> 8;
     CrcLo = CheckSum;
}   

uint16_t CalcCRC1(uint8_t *ptr,uint8_t Length,uint16_t verify)
{
     uint8_t i,CrcData;
     uint16_t CheckSum = 0xFFFF;
     while (Length --)
     {
        CrcData = * (ptr ++);
        for (i=0u;i<8u;i++)
        {
           if (((CheckSum & 0x8000) >> 8) ^ (CrcData & 0x80))
              CheckSum = (CheckSum << 1) ^ verify;
           else
              CheckSum = (CheckSum << 1);
           CrcData <<= 1;
        }   
     }
		 return CheckSum;
     //CrcHi = CheckSum >> 8;
     //CrcLo = CheckSum;
}   
